using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;

namespace Madason.MetaModel.Interfaces.Tests
{
	[TestFixture]
	public class TestXmi11Export
	{
		protected Model ExportAndImport(Model model)
		{
			
			ExportXmi11 export = new ExportXmi11();
			StringWriter writer = new StringWriter();
			export.Export(model, writer);

			string umlDoc = writer.ToString();
			StreamWriter debugWriter = new StreamWriter("test.xmi");
			debugWriter.Write(umlDoc);
			debugWriter.Close();
			
			//StringReader reader = new StringReader(umlDoc);
			using (StreamReader reader = new StreamReader("test.xmi"))
			{
				ImportXmi11 import = new ImportXmi11();
				Model copy = import.Import(reader);
				return copy;
			}
		}

		[Test]
		public void TestNamespaces()
		{
			Model model = new Model();
			Namespace ns1 = new Namespace();
			Namespace ns2 = new Namespace();

			ns1.Name = "Namespace1";
			ns2.Name = "Namespace2";
			model.Namespaces.Add(ns1);
			ns1.Parent = model;
			ns1.Namespaces.Add(ns2);
			ns2.Parent = ns1;

			Class cls1 = new Class();
			cls1.Namespace = ns1;
			ns1.Classes.Add(cls1);
			cls1.Name = "Class1";
			Attribute attr1 = new Attribute();
			attr1.Class = cls1;
			cls1.Attributes.Add(attr1);
			attr1.Name = "username";


			Model copy = ExportAndImport(model);

			Assert.AreEqual(1, copy.Namespaces.Count);
		}
	}
}
